﻿namespace Sidvall.AuthorizationManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class AuthorizationScopeUser : global::Sidvall.AuthorizationManager.UI.Entities.Core.BusinessBase, global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser
    {
        #region Business Members

        #region AccessTime

        private System.Nullable<System.DateTime> _AccessTime = null;
        partial void OnBeforeAccessTimePropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnBeforeAccessTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterAccessTimePropertyChanged();
        public System.Nullable<System.DateTime> AccessTime
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>>(Sidvall.Business.ValidationManager.GetValidDateTime(_AccessTime));
                OnBeforeAccessTimePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _AccessTime);
                OnBeforeAccessTimePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("AccessTime", eventData.Value, true, true, true);
                    OnAfterAccessTimePropertyChanged();
                }
            }
        }

        #endregion
        #region AuthorizationScopeId

        private long _AuthorizationScopeId = 0L;
        partial void OnBeforeAuthorizationScopeIdPropertyGet(Sidvall.Business.PropertyEventData<long> eventData);
        partial void OnBeforeAuthorizationScopeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterAuthorizationScopeIdPropertyChanged();
        public long AuthorizationScopeId
        {
            get
            {
                Sidvall.Business.PropertyEventData<long> eventData = new Sidvall.Business.PropertyEventData<long>(_AuthorizationScopeId);
                OnBeforeAuthorizationScopeIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _AuthorizationScopeId);
                OnBeforeAuthorizationScopeIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("AuthorizationScopeId", eventData.Value, true, true, true);
                    OnAfterAuthorizationScopeIdPropertyChanged();
                }
            }
        }

        #endregion
        #region CreatedTime

        private System.DateTime _CreatedTime = System.DateTime.UtcNow;
        partial void OnBeforeCreatedTimePropertyGet(Sidvall.Business.PropertyEventData<System.DateTime> eventData);
        partial void OnBeforeCreatedTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData);
        partial void OnAfterCreatedTimePropertyChanged();
        public System.DateTime CreatedTime
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.DateTime> eventData = new Sidvall.Business.PropertyEventData<System.DateTime>(Sidvall.Business.ValidationManager.GetValidDateTime(_CreatedTime));
                OnBeforeCreatedTimePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData = new Sidvall.Business.PropertyChangeEventData<System.DateTime>(value, _CreatedTime);
                OnBeforeCreatedTimePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("CreatedTime", eventData.Value, true, true, true);
                    OnAfterCreatedTimePropertyChanged();
                }
            }
        }

        #endregion
        #region IsActive

        private bool _IsActive = false;
        partial void OnBeforeIsActivePropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeIsActivePropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsActivePropertyChanged();
        public bool IsActive
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_IsActive);
                OnBeforeIsActivePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsActive);
                OnBeforeIsActivePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("IsActive", eventData.Value, true, true, true);
                    OnAfterIsActivePropertyChanged();
                }
            }
        }

        #endregion
        #region UpdatedTime

        private System.DateTime _UpdatedTime = System.DateTime.UtcNow;
        partial void OnBeforeUpdatedTimePropertyGet(Sidvall.Business.PropertyEventData<System.DateTime> eventData);
        partial void OnBeforeUpdatedTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData);
        partial void OnAfterUpdatedTimePropertyChanged();
        public System.DateTime UpdatedTime
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.DateTime> eventData = new Sidvall.Business.PropertyEventData<System.DateTime>(Sidvall.Business.ValidationManager.GetValidDateTime(_UpdatedTime));
                OnBeforeUpdatedTimePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData = new Sidvall.Business.PropertyChangeEventData<System.DateTime>(value, _UpdatedTime);
                OnBeforeUpdatedTimePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("UpdatedTime", eventData.Value, true, true, true);
                    OnAfterUpdatedTimePropertyChanged();
                }
            }
        }

        #endregion
        #region UserClaims

        private string _UserClaims = string.Empty;
        partial void OnBeforeUserClaimsPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeUserClaimsPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterUserClaimsPropertyChanged();
        public string UserClaims
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_UserClaims);
                OnBeforeUserClaimsPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _UserClaims);
                OnBeforeUserClaimsPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("UserClaims", eventData.Value, true, true, true);
                    OnAfterUserClaimsPropertyChanged();
                }
            }
        }

        #endregion
        #region UserContext

        private string _UserContext = string.Empty;
        partial void OnBeforeUserContextPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeUserContextPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterUserContextPropertyChanged();
        public string UserContext
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_UserContext);
                OnBeforeUserContextPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _UserContext);
                OnBeforeUserContextPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("UserContext", eventData.Value, true, true, true);
                    OnAfterUserContextPropertyChanged();
                }
            }
        }

        #endregion
        #region UserId

        private string _UserId = string.Empty;
        partial void OnBeforeUserIdPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeUserIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterUserIdPropertyChanged();
        public string UserId
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_UserId);
                OnBeforeUserIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _UserId);
                OnBeforeUserIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("UserId", eventData.Value, true, true, true);
                    OnAfterUserIdPropertyChanged();
                }
            }
        }

        #endregion
        #region AuthorizationScope

        private AuthorizationScope _AuthorizationScope;
        partial void OnBeforeAuthorizationScopePropertyChanged(Sidvall.Business.PropertyChangeEventData<AuthorizationScope> eventData);
        partial void OnAfterAuthorizationScopePropertyChanged();
        public AuthorizationScope AuthorizationScope
        {
            get
            {
                return _AuthorizationScope;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<AuthorizationScope> eventData = new Sidvall.Business.PropertyChangeEventData<AuthorizationScope>(value, _AuthorizationScope);
                OnBeforeAuthorizationScopePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("AuthorizationScope", eventData.Value, true, true, false);
                    OnAfterAuthorizationScopePropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowIsValid

        public override bool DataRowIsValid(Sidvall.Data.BusinessRuleFilter filter)
        {
            return global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.DataRowIsValid(this, filter);
        }

        #endregion
        #region DataRowStateIsDirty

        public override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.DataRowStateIsDirty(this);
            }
        }

        #endregion

        #region LoadAuthorizationScopeAsync

        public async System.Threading.Tasks.Task<AuthorizationScope> LoadAuthorizationScopeAsync()
        {
            return await LoadAuthorizationScopeAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<AuthorizationScope> LoadAuthorizationScopeAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeUserManager.LoadAuthorizationScopeAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.AuthorizationScope;
        }
        public AuthorizationScope LoadAuthorizationScope(AuthorizationScope item)
        {
            LoadInstanceField("AuthorizationScope", item, true, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public AuthorizationScopeUser Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public AuthorizationScopeUser Copy()
        {
            return Copy(null);
        }
        public AuthorizationScopeUser Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new AuthorizationScopeUser();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(AuthorizationScopeUser destination, global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser source, Sidvall.Data.CopySettings copySettings);
        private void Import(AuthorizationScopeUser destination, global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(AuthorizationScopeUser destination, AuthorizationScopeUser source, Sidvall.Data.CopySettings copySettings);
        private void Import(AuthorizationScopeUser destination, AuthorizationScopeUser source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<AuthorizationScopeUser> SaveItemAsync()
        {
            return await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeUserManager.SaveItemAsync(this);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeUser> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeUserManager.SaveItemAsync(this, mode);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeUser> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeUserManager.SaveItemAsync(this, settings);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeUser> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeUserManager.SaveItemAsync(this, settings, strategyContext, objectParameters);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.Initialize(this, settings);
        }

        #endregion
        
        #region IAuthorizationScopeUser Members

        System.Nullable<System.DateTime> global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.AccessTime
        {
            get
            {
                return this._AccessTime;
            }
            set
            {
                this._AccessTime = value;
            }
        }
        long global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.AuthorizationScopeId
        {
            get
            {
                return this._AuthorizationScopeId;
            }
            set
            {
                this._AuthorizationScopeId = value;
            }
        }
        System.DateTime global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.CreatedTime
        {
            get
            {
                return this._CreatedTime;
            }
            set
            {
                this._CreatedTime = value;
            }
        }
        bool global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.IsActive
        {
            get
            {
                return this._IsActive;
            }
            set
            {
                this._IsActive = value;
            }
        }
        System.DateTime global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.UpdatedTime
        {
            get
            {
                return this._UpdatedTime;
            }
            set
            {
                this._UpdatedTime = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.UserClaims
        {
            get
            {
                return this._UserClaims;
            }
            set
            {
                this._UserClaims = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.UserContext
        {
            get
            {
                return this._UserContext;
            }
            set
            {
                this._UserContext = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.UserId
        {
            get
            {
                return this._UserId;
            }
            set
            {
                this._UserId = value;
            }
        }
        global::Sidvall.AuthorizationManager.Data.IAuthorizationScope global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.AuthorizationScope
        {
            get
            {
                return this._AuthorizationScope;
            }
            set
            {
                UpdateChildProperty(this._AuthorizationScope, value);
                this._AuthorizationScope = value as AuthorizationScope;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public AuthorizationScopeUser()
        {
        }

        public AuthorizationScopeUser(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}